package com.sx.zongzhi.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import com.sx.zongzhi.BaseActivity;
import com.sx.zongzhi.MyApplication;
import com.sx.zongzhi.R;
import com.sx.zongzhi.bean.UserBean;

import butterknife.ButterKnife;
import xiaofei.library.datastorage.DataStorageFactory;
import xiaofei.library.datastorage.IDataStorage;

public class SplashActivity extends BaseActivity {

    @Override
    public void setUI(Bundle savedInstanceState) {
        setContentView(R.layout.activity_splash);
        ButterKnife.bind(this);
        setGoneTitle();
        openApp();
    }

    private void openApp() {
        IDataStorage dataStorage=DataStorageFactory.getInstance(
                getApplicationContext(),
                DataStorageFactory.TYPE_DATABASE);
        if (dataStorage.contains(UserBean.class,getPackageName())){
            new Handler().postDelayed(runnableMain, 2000);//进入主页
            UserBean userBean=dataStorage.load(UserBean.class,getPackageName());
            MyApplication.sid=userBean.getSid();
        }else {
            new Handler().postDelayed(runnableLogin, 2000);//登录
        }

    }

    private Runnable runnableLogin = new Runnable() {
        @Override
        public void run() {
            startActivity(new Intent(SplashActivity.this, LoginActivity.class));
            finish();
        }
    };
    private Runnable runnableMain = new Runnable() {
        @Override
        public void run() {
            startActivity(new Intent(SplashActivity.this, MainActivity.class));
            finish();
        }
    };


}
